<!DOCTYPE html>
<html>
<head>
    <title>Wheel of Fortune</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <style>
        canvas {
            display: block;
            margin: 20px auto;
        }
        #controls {
            text-align: center;
            margin: 20px;
        }
        
        .modal {
            display: none;
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background: white;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0,0,0,0.3);
            z-index: 1000;
            text-align: center;
        }
        
        .modal h2 {
            margin-top: 0;
            color: #e31b1b;
        }
        
        .modal .winner {
            font-size: 36px;
            margin: 20px 0;
        }
        
        .modal button {
            padding: 8px 20px;
            margin: 5px;
            cursor: pointer;
        }
        
        .firework {
            position: fixed;
            pointer-events: none;
            will-change: transform;
            transform: translate3d(0, 0, 0);
        }
        
        .info-container {
            display: flex;
            justify-content: space-around;
            max-width: 800px;
            margin: 30px auto;
            padding: 0 20px;
            gap: 20px;
            width: 100%;
            box-sizing: border-box;
        }
        
        .info-box {
            flex: 1;
            background: white;
            border-radius: 10px;
            padding: 20px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            min-width: 0;
            box-sizing: border-box;
        }
        
        .info-box h3 {
            color: #333;
            margin-top: 0;
            margin-bottom: 15px;
            padding-bottom: 10px;
            border-bottom: 2px solid #eee;
            font-size: 18px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        
        .info-box ul {
            list-style: none;
            padding: 0;
            margin: 0;
        }
        
        .info-box ul li {
            padding: 8px 0;
            color: #666;
            cursor: pointer;
            transition: color 0.3s ease;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        
        .info-box ul li:hover {
            color: #1a73e8;
        }
        
        .stats .stat-item {
            display: flex;
            justify-content: space-between;
            padding: 10px 0;
            border-bottom: 1px solid #eee;
        }
        
        .stats .stat-item:last-child {
            border-bottom: none;
        }
        
        .stat-label {
            color: #666;
            margin-right: 10px;
        }
        
        .stat-value {
            color: #1a73e8;
            font-weight: bold;
        }
        
        /* 頂部導航欄樣式 */
        .top-nav {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 10px 20px;
            background: #4285f4;
            color: white;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            z-index: 1000;
        }

        .nav-left {
            display: flex;
            align-items: center;
            gap: 15px;
        }

        .nav-right {
            display: flex;
            align-items: center;
            gap: 20px;
            position: relative;
        }

        .logo {
            height: 30px;
            width: auto;
        }

        .site-name {
            font-size: 18px;
            font-weight: 500;
        }

        .nav-btn {
            color: white;
            text-decoration: none;
            padding: 8px 16px;
            border-radius: 4px;
            transition: background-color 0.3s;
        }

        .nav-btn:hover {
            background: rgba(255,255,255,0.1);
        }

        .language-selector select {
            background: transparent;
            border: none;
            color: white;
            padding: 8px;
            cursor: pointer;
            font-size: 16px;
        }

        .language-selector select option {
            background: white;
            color: black;
        }

        .menu-toggle {
            display: none; /* PC端默認隱藏 */
        }

        .nav-menu {
            display: none;
            position: absolute;
            top: 100%;
            right: 0;
            background: white;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            padding: 8px 0;
            margin-top: 10px;
            min-width: 200px;
            z-index: 1001;
        }

        .nav-menu.active {
            display: block;
        }

        .nav-menu .nav-btn {
            color: #333;
            display: block;
            width: 100%;
            text-align: left;
            padding: 12px 20px;
            box-sizing: border-box;
        }

        .nav-menu .nav-btn:hover {
            background: #f5f5f5;
        }

        /* 移動端適配 */
        @media screen and (max-width: 768px) {
            .desktop-nav {
                display: none; /* 隱藏PC端導航 */
            }

            .menu-toggle {
                display: flex; /* 顯示選單按鈕 */
                align-items: center;
                gap: 8px;
                background: transparent;
                border: none;
                color: white;
                cursor: pointer;
                padding: 8px 16px;
                font-size: 16px;
                border-radius: 4px;
            }

            .menu-text {
                display: none; /* 移動端隱藏Menu文字 */
            }

            .nav-menu {
                right: 10px;
                width: calc(100% - 20px);
                max-width: 300px;
            }

            .site-name {
                display: none;
            }

            .nav-right {
                gap: 10px;
            }
        }

        /* 小屏幕手機適配 */
        @media screen and (max-width: 480px) {
            .top-nav {
                padding: 8px 12px;
            }

            .nav-btn {
                padding: 6px 12px;
                font-size: 14px;
            }
        }

        /* 右側歷史記錄面板樣式 */
        .results-panel {
            width: 300px;
            background: white;
            box-shadow: -2px 0 5px rgba(0,0,0,0.1);
            padding: 20px;
            position: fixed;
            right: 0;
            top: 60px;
            bottom: 0;
            overflow-y: auto;
        }

        .panel-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 15px;
            padding-bottom: 10px;
            border-bottom: 1px solid #eee;
        }

        .panel-header h3 {
            margin: 0;
            font-size: 16px;
            color: #333;
        }

        .results-textarea {
            width: 100%;
            height: 150px;
            border: 1px solid #eee;
            border-radius: 4px;
            padding: 10px;
            resize: none;
            font-family: Arial, sans-serif;
            line-height: 1.5;
            font-size: 14px;
            background-color: #fafafa;
        }

        .results-textarea:focus {
            outline: none;
            border-color: #4285f4;
            background-color: #fff;
        }

        .result-count {
            background: #4285f4;
            color: white;
            padding: 2px 8px;
            border-radius: 10px;
            font-size: 0.8em;
        }

        .panel-controls button {
            padding: 5px;
            background: transparent;
            border: none;
            color: #666;
            cursor: pointer;
            border-radius: 4px;
        }

        .panel-controls button:hover {
            background: #f0f0f0;
            color: #4285f4;
        }

        /* 語言選擇器樣式 */
        .language-selector select {
            padding: 5px 10px;
            border: none;
            background: transparent;
            color: white;
            cursor: pointer;
        }

        .language-selector select option {
            color: black;
            background: white;
        }

        /* 頂部導航欄樣式 */
        .top-nav {
            padding: 8px 16px;
            background: #4285f4;
            color: white;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            z-index: 1000;
        }

        /* 為了防止內容被固定導航欄遮擋，添加上邊距 */
        #controls {
            margin-top: 60px;
        }

        .tabs {
            display: flex;
            gap: 10px;
            margin-bottom: 15px;
            border-bottom: 1px solid #eee;
        }

        .tab-btn {
            padding: 8px 16px;
            border: none;
            background: none;
            cursor: pointer;
            color: #666;
            position: relative;
        }

        .tab-btn.active {
            color: #4285f4;
        }

        .tab-btn.active::after {
            content: '';
            position: absolute;
            bottom: -1px;
            left: 0;
            right: 0;
            height: 2px;
            background: #4285f4;
        }

        .count {
            background: #e8f0fe;
            color: #4285f4;
            padding: 2px 6px;
            border-radius: 10px;
            font-size: 12px;
            margin-left: 5px;
        }

        .tab-pane {
            display: none;
        }

        .tab-pane.active {
            display: block;
        }

        .entries-list {
            display: flex;
            flex-direction: column;
            gap: 8px;
        }

        .entry-item {
            display: flex;
        }

        .entry-input {
            flex: 1;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 14px;
        }

        .entry-input:focus {
            border-color: #4285f4;
            outline: none;
            box-shadow: 0 0 0 2px rgba(66, 133, 244, 0.2);
        }

        .add-entry-btn {
            width: 100%;
            padding: 8px;
            margin-top: 10px;
            border: 1px dashed #4285f4;
            background: white;
            color: #4285f4;
            border-radius: 4px;
            cursor: pointer;
        }

        .add-entry-btn:hover {
            background: #f8f9fa;
        }

        /* 響應式佈局樣式 */
        @media screen and (max-width: 768px) {
            .main-container {
                flex-direction: column;
                margin-top: 120px; /* 為導航欄留出空間 */
            }

            .input-section {
                width: 100%;
                position: static; /* 移除 fixed 定位 */
                height: auto;
                margin: 20px 0;
                box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            }

            .left-section {
                width: 100%;
            }

            .wheel-section {
                margin-bottom: 20px;
            }

            #controls {
                margin: 20px 0;
            }

            /* 移除之前的 order 屬性 */
            .wheel-section,
            .input-section,
            .info-container {
                order: unset;
            }

            /* 調整內容間距 */
            .info-container {
                margin-top: 30px;
            }

            /* 確保內容不會被導航欄遮擋 */
            body {
                padding-top: 60px;
            }

            /* 調整標籤頁在移動端的顯示 */
            .tabs {
                position: static;
                padding: 10px 0;
            }

            /* 調整文本區域在移動端的高度 */
            .entries-textarea,
            .results-textarea {
                min-height: 150px;
            }
        }

        /* 針對更小屏幕的優化 */
        @media screen and (max-width: 480px) {
            .main-container {
                padding: 10px;
            }

            .input-section {
                padding: 15px;
            }

            .control-btn {
                padding: 8px 16px;
                font-size: 14px;
            }
        }

        /* 確保內容不會被固定導航欄遮擋 */
        @media screen and (max-height: 600px) {
            .results-panel {
                max-height: 60vh;
                overflow-y: auto;
            }
        }

        /* 優化觸摸設備的交互 */
        @media (hover: none) {
            .nav-btn:active {
                background: rgba(255,255,255,0.2);
            }

            .entry-input {
                padding: 10px 8px; /* 增加點擊區域 */
            }

            .add-entry-btn {
                padding: 12px 8px;
            }
        }

        .main-container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        .wheel-section {
            width: 100%;
            max-width: 500px;
            margin-bottom: 30px;
            text-align: center;
        }

        .input-section {
            width: 100%;
            max-width: 800px;
            margin: 30px auto;
            padding: 20px;
            background: white;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            box-sizing: border-box;
        }

        canvas {
            max-width: 500px;
            width: 100%;
            height: auto;
            margin: 20px auto;
        }

        .tabs {
            display: flex;
            gap: 15px;
            margin-bottom: 20px;
            border-bottom: 1px solid #eee;
            overflow-x: auto;
            -webkit-overflow-scrolling: touch;
            scrollbar-width: none; /* Firefox */
        }

        .tabs::-webkit-scrollbar {
            display: none; /* Chrome, Safari */
        }

        .tab-btn {
            padding: 10px 20px;
            border: none;
            background: none;
            color: #666;
            cursor: pointer;
            white-space: nowrap;
            position: relative;
            transition: color 0.3s ease;
        }

        .tab-btn.active {
            color: #4285f4;
        }

        .tab-btn.active::after {
            content: '';
            position: absolute;
            bottom: -1px;
            left: 0;
            right: 0;
            height: 2px;
            background: #4285f4;
        }

        .tab-content {
            position: relative;
            min-height: 150px;
            width: 100%;
            box-sizing: border-box;
        }

        .tab-pane {
            display: none;
            width: 100%;
            box-sizing: border-box;
        }

        .tab-pane.active {
            display: block;
        }

        .entries-textarea,
        .results-textarea {
            width: 100%;
            box-sizing: border-box;
            margin: 0;
            display: block;
        }

        /* 確保 input-section 內的所有元素都使用 border-box */
        .input-section * {
            box-sizing: border-box;
        }

        /* 移動端適配 */
        @media screen and (max-width: 768px) {
            .tab-content {
                min-height: 120px;
                padding: 0;
            }

            .entries-textarea,
            .results-textarea {
                min-height: 120px;
            }
        }

        /* 小屏幕手機適配 */
        @media screen and (max-width: 480px) {
            .input-section {
                margin: 10px auto;
                padding: 10px;
            }

            .tabs {
                gap: 8px;
                margin-bottom: 12px;
            }

            .tab-btn {
                padding: 6px 12px;
                font-size: 13px;
            }

            .entries-textarea,
            .results-textarea {
                padding: 8px;
                border-radius: 4px;
            }
        }

        /* 確保在不同設備上的間距一致性 */
        @media screen and (min-width: 769px) {
            .input-section {
                margin: 40px auto;
            }
        }

        /* 統一容器樣式 */
        .input-section,
        .info-container {
            width: 100%;
            max-width: 800px;
            margin: 30px auto;
            padding: 20px;
            box-sizing: border-box;
        }

        .input-section {
            background: white;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }

        /* 移動端適配 */
        @media screen and (max-width: 768px) {
            .input-section,
            .info-container {
                margin: 15px auto;
                padding: 15px;
                width: calc(100% - 30px); /* 確右各有15px邊距 */
            }

            .input-section {
                border-radius: 8px;
            }

            .info-box {
                border-radius: 8px;
                margin-bottom: 15px;
            }

            /* 確保文本區域和信息框內容對齊 */
            .entries-textarea,
            .results-textarea,
            .info-box {
                padding: 12px;
                border-radius: 8px;
            }
        }

        /* 小屏幕手機適配 */
        @media screen and (max-width: 480px) {
            .input-section,
            .info-container {
                margin: 10px auto;
                padding: 10px;
                width: calc(100% - 20px); /* 確保左右各有10px邊距 */
            }

            .input-section,
            .info-box {
                border-radius: 6px;
            }

            .entries-textarea,
            .results-textarea {
                padding: 10px;
                border-radius: 6px;
            }
        }

        /* 確保內容在不同設備上的一致性 */
        @media screen and (min-width: 769px) {
            .input-section,
            .info-container {
                margin: 40px auto;
            }
        }

        /* 統一內容區域樣式 */
        .tab-content,
        .info-box {
            background: white;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }

        /* 暗色主題支持 */
        @media (prefers-color-scheme: dark) {
            .input-section,
            .info-box {
                background: #2d2d2d;
                box-shadow: 0 2px 10px rgba(0,0,0,0.2);
            }

            .entries-textarea,
            .results-textarea {
                background: #1f1f1f;
                border-color: #444;
                color: #fff;
            }
        }

        /* 移動端適配 */
        @media screen and (max-width: 768px) {
            .info-container {
                flex-direction: column;
                margin: 15px auto;
                padding: 0 15px;
                gap: 15px;
                width: calc(100% - 30px);  /* 確保左右各有15px邊距 */
            }
            
            .info-box {
                width: 100%;
                padding: 15px;
                margin: 0;
                flex: none;  /* 移除 flex 屬性 */
            }

            .info-box h3 {
                font-size: 16px;
                margin-bottom: 10px;
                padding-bottom: 8px;
            }

            .info-box ul li {
                padding: 6px 0;
                font-size: 14px;
            }

            .stats .stat-item {
                padding: 8px 0;
            }

            .stat-label,
            .stat-value {
                font-size: 14px;
            }
        }

        /* 小屏幕手機適配 */
        @media screen and (max-width: 480px) {
            .info-container {
                margin: 10px auto;
                padding: 0 10px;
                gap: 10px;
                width: calc(100% - 20px);  /* 確保左右各有10px邊距 */
            }
            
            .info-box {
                padding: 12px;
                border-radius: 8px;
            }

            .info-box h3 {
                font-size: 15px;
                margin-bottom: 8px;
                padding-bottom: 6px;
            }

            .info-box ul li {
                padding: 5px 0;
                font-size: 13px;
            }
        }

        /* 平板適配 */
        @media screen and (min-width: 769px) and (max-width: 1024px) {
            .info-container {
                padding: 0 30px;
                gap: 30px;
            }
            
            .info-box {
                padding: 15px;
            }
        }

        .dropdown-container {
            position: relative;
            display: inline-block;
        }

        .menu-toggle {
            display: none;
            background: transparent;
            border: none;
            color: white;
            cursor: pointer;
            padding: 8px;
            font-size: 20px;
            transition: transform 0.3s;
        }

        .nav-menu {
            display: none;
            position: absolute;
            top: 100%;
            right: 0;
            background: white;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            border-radius: 4px;
            padding: 10px;
            margin-top: 5px;
            min-width: 200px;
            opacity: 0;
            transform: translateY(-10px);
            transition: opacity 0.3s, transform 0.3s;
        }

        /* 懸停時顯示選單 */
        .dropdown-container:hover .nav-menu {
            display: block;
            opacity: 1;
            transform: translateY(0);
        }

        /* 移動端適配 */
        @media screen and (max-width: 768px) {
            .menu-toggle {
                display: block;
            }

            .nav-btn:not(.visible-btn) {
                display: none;
            }

            .dropdown-container:hover .menu-toggle {
                transform: rotate(90deg);
            }

            .nav-menu .nav-btn {
                display: block;
            }
        }

        .nav-menu {
            display: none;
            position: absolute;
            top: 100%;
            right: 0;
            background: white;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            border-radius: 4px;
            padding: 10px;
            margin-top: 5px;
            min-width: 200px;
            opacity: 0;
            transform: translateY(-10px);
            transition: opacity 0.3s, transform 0.3s;
        }

        .nav-menu.active {
            display: block;
            opacity: 1;
            transform: translateY(0);
        }

        .menu-toggle {
            display: none;
            background: transparent;
            border: none;
            color: white;
            cursor: pointer;
            padding: 8px;
            font-size: 20px;
            transition: transform 0.3s;
        }

        .menu-toggle.active {
            transform: rotate(90deg);
        }

        .language-selector.visible-btn select {
            color: white;
            background: transparent;
            border: none;
            cursor: pointer;
            padding: 8px 16px;
            font-size: inherit;
        }

        .language-selector.visible-btn select option {
            color: black;
            background: white;
        }

        /* 移動端適配 */
        @media screen and (max-width: 768px) {
            .menu-toggle {
                display: block;
            }

            .nav-btn:not(.visible-btn),
            .language-selector:not(.visible-btn) {
                display: none;
            }

            .nav-menu .nav-btn {
                display: block;
                width: 100%;
                text-align: left;
                color: #333;
            }

            .nav-menu .nav-btn:hover {
                background: #f5f5f5;
            }
        }

        /* 修改按鈕樣式 */
        .controls-wrapper {
            display: flex;
            gap: 15px;
            justify-content: center;
            align-items: center;
        }

        .control-btn {
            padding: 12px 24px;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-size: 16px;
            color: white;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            justify-content: center;  /* 確保所有內容居中 */
            text-align: center;
            white-space: nowrap;
        }

        /* Sound 按鈕樣式 */
        .sound-btn {
            background-color: #dc3545;  /* 默認紅色（關閉狀）*/
            min-width: 50px;
            padding: 12px;
            justify-content: center;
        }

        .sound-btn.enabled {
            background-color: #28a745;  /* 開啟狀態為綠色 */
        }

        /* 聲音圖標樣式 */
        .sound-icon {
            display: inline-block;
            width: 20px;
            height: 20px;
            background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M3.63 3.63a.996.996 0 000 1.41L7.29 8.7 7 9H4c-.55 0-1 .45-1 1v4c0 .55.45 1 1 1h3l3.29 3.29c.63.63 1.71.18 1.71-.71v-4.17l4.18 4.18c-.49.37-1.02.68-1.6.91-.36.15-.58.53-.58.92 0 .72.73 1.18 1.39.91.8-.33 1.55-.77 2.22-1.31l1.34 1.34a.996.996 0 101.41-1.41L5.05 3.63c-.39-.39-1.02-.39-1.42 0zM19 12c0 .82-.15 1.61-.41 2.34l1.53 1.53c.56-1.17.88-2.48.88-3.87 0-3.83-2.4-7.11-5.78-8.4-.59-.23-1.22.23-1.22.86v.19c0 .38.25.71.61.85C17.18 6.54 19 9.06 19 12zm-8.71-6.29l-.17.17L12 7.76V6.41c0-.89-1.08-1.33-1.71-.7zM16.5 12c0-1.77-1.02-3.29-2.5-4.03v1.79l2.48 2.48c.01-.08.02-.16.02-.24z'/%3E%3C/svg%3E");
            background-size: contain;
            background-repeat: no-repeat;
            background-position: center;
        }

        .sound-btn.enabled .sound-icon {
            background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z'/%3E%3C/svg%3E");
        }

        /* 移動端適配 */
        @media screen and (max-width: 768px) {
            .sound-btn {
                min-width: 40px;
                padding: 10px;
            }

            .sound-icon {
                width: 18px;
                height: 18px;
            }
        }

        /* Spin/Stop 按鈕樣式 */
        .spin-btn {
            background-color: #28a745;
            min-width: 150px;
            font-weight: bold;
            padding: 12px 30px;  /* 增加水平內邊距 */
        }

        .spin-btn[data-state="stop"] {
            background-color: #dc3545;
        }

        /* 禁用狀態 */
        .control-btn:disabled {
            opacity: 0.7;
            cursor: not-allowed;
        }

        /* 懸停效果 */
        .control-btn:not(:disabled):hover {
            transform: scale(1.05);
            opacity: 0.9;
        }

        /* 控制按鈕容器 */
        .controls-wrapper {
            display: flex;
            gap: 20px;  /* 增加按鈕間距 */
            justify-content: center;
            align-items: center;
        }

        /* 移動端適配 */
        @media screen and (max-width: 768px) {
            .control-btn {
                padding: 10px 20px;
                font-size: 14px;
            }

            .sound-btn {
                min-width: 40px;
                padding: 10px;
            }

            .spin-btn {
                min-width: 120px;
                padding: 10px 24px;
            }

            .controls-wrapper {
                gap: 15px;
            }
        }

        /* 始終顯示的導航項樣式 */
        .always-visible {
            display: flex !important; /* 強制顯示 */
        }

        /* 移動端適配 */
        @media screen and (max-width: 768px) {
            .nav-right {
                gap: 15px;
            }

            .nav-menu {
                margin-top: 15px;
                right: -10px; /* 調整位置 */
            }

            .menu-text {
                display: none;
            }

            .menu-toggle {
                display: flex;
                align-items: center;
                padding: 8px;
                background: transparent;
                border: none;
                color: white;
                cursor: pointer;
            }

            .menu-icon {
                font-size: 20px;
            }

            /* 語言選擇器移動端樣式 */
            .language-selector select {
                padding: 5px;
                font-size: 14px;
            }
        }

        /* 小屏幕手機適配 */
        @media screen and (max-width: 480px) {
            .top-nav {
                padding: 8px 12px;
            }

            .nav-menu {
                width: 200px;
                right: -5px;
            }
        }

        .nav-center {
            display: flex;
            align-items: center;
            gap: 20px;
        }

        .desktop-nav {
            display: flex; /* PC端默認顯示 */
        }

        .menu-toggle,
        .nav-menu {
            display: none; /* PC端默認隱藏 */
        }

        /* 移動端適配 */
        @media screen and (max-width: 768px) {
            .desktop-nav {
                display: none; /* 隱藏PC端導航 */
            }

            .menu-toggle {
                display: flex; /* 顯示選單按鈕 */
                align-items: center;
                gap: 8px;
                background: transparent;
                border: none;
                color: white;
                cursor: pointer;
                padding: 8px;
                font-size: 20px;
            }

            .nav-menu {
                display: none;
                position: absolute;
                top: 100%;
                right: 0;
                background: white;
                border-radius: 8px;
                box-shadow: 0 2px 10px rgba(0,0,0,0.1);
                padding: 8px 0;
                margin-top: 10px;
                min-width: 200px;
                z-index: 1001;
            }

            .nav-menu.active {
                display: block;
            }

            .menu-text {
                display: none;
            }

            .nav-right {
                position: relative;
            }
        }

        /* 始終顯示的導航項樣式 */
        .always-visible {
            display: flex !important;
        }

        /* 移動端適配 */
        @media screen and (max-width: 768px) {
            .nav-right {
                display: flex;
                align-items: center;
                gap: 10px;
            }

            .always-visible {
                display: flex !important;
            }

            /* 調整語言選擇器在移動端的樣式 */
            .language-selector.always-visible select {
                padding: 5px;
                font-size: 14px;
                min-width: 80px;
            }

            /* 調整FAQ按鈕在移動端的樣式 */
            .nav-btn.always-visible {
                padding: 6px 12px;
                font-size: 14px;
            }
        }
    </style>
</head>
<body>
    <header>
        <nav class="top-nav">
            <div class="nav-left">
                <a href="index.html">
                    <img src="images/logo.png" alt="標誌" class="logo">
                    <span class="site-name">幸運轉盤</span>
                </a>
            </div>
            
            <!-- PC端導航選單 -->
            <div class="nav-center desktop-nav">
                <a href="gallery.html" class="nav-btn">圖庫</a>
                <a href="blog.html" class="nav-btn">部落格</a>
                <a href="about.html" class="nav-btn">關於</a>
                <a href="privacy-terms.html" class="nav-btn">隱私權和條款</a>
            </div>
            
            <div class="nav-right">
                <a href="faq.html" class="nav-btn always-visible">常見問題</a>
                <div class="language-selector always-visible">
                    <select onchange="changeLanguage(this.value)">
                        <a href="/">English</a>
                        <option value="zh-TW" selected>繁體中文</option>
                        <option value="zh-CN">简体中文</option>    
                        <option value="es">Español</option>
                        <option value="fr">Français</option>
                        <option value="de">Deutsch</option>
                        <option value="ja">日本語</option>
                        <option value="ko">한국어</option>
                    </select>
                </div>
                
                <!-- 移動端選單按鈕 -->
                <button class="menu-toggle" onclick="toggleMenu()">
                    <span class="menu-icon">☰</span>
                    <span class="menu-text">選單</span>
                </button>
            </div>
        </nav>
    </header>

    <div class="main-container">
        <!-- 轉盤部分 -->
        <div class="wheel-section">
            <canvas id="wheelCanvas" width="500" height="500"></canvas>
            <audio id="spinSound" src="sounds/spin.mp3" style="display:none"></audio>
            <audio id="applauseSound" src="sounds/applause.mp3" style="display:none"></audio>
            <div id="controls">
                <div class="controls-wrapper">
                    <button class="control-btn sound-btn" onclick="toggleSound()">
                        <i class="sound-icon"></i>
                    </button>
                    <button class="control-btn spin-btn" onclick="handleSpinClick()">開始轉動</button>
                </div>
            </div>
        </div>

        <!-- 輸入部分 -->
        <div class="input-section">
            <div class="tabs">
                <button class="tab-btn active" data-tab="entries">
                    參與者 <span class="count">8</span>
                </button>
                <button class="tab-btn" data-tab="results">
                    結果 <span class="count">0</span>
                </button>
            </div>

            <div class="tab-content">
                <div class="tab-pane active" id="entries-tab">
                    <textarea class="entries-textarea" placeholder="輸入名字（每行一個）">阿里
碧翠絲
查爾斯
黛雅
艾瑞克
法蒂瑪
加百列
漢娜</textarea>
                </div>

                <div class="tab-pane" id="results-tab">
                    <textarea readonly class="results-textarea" placeholder="中獎者將在此顯示..."></textarea>
                </div>
            </div>
        </div>

        <!-- 統計信息部分 -->
        <div class="info-container">
            <div class="info-box">
                <h3>部落格文章</h3>
                <ul>
                    <li>課堂上的隨機點名器</li>
                    <li>如何使用轉盤</li>
                    <li>轉盤更新 - 2024年3月</li>
                </ul>
            </div>
            
            <div class="info-box">
                <h3>常見問題</h3>
                <ul>
                    <li>轉盤可以用來做什麼？</li>
                    <li>我的資料安全嗎？</li>
                    <li>結果公平嗎？</li>
                    <li>如何自訂轉盤？</li>
                </ul>
            </div>
            
            <div class="info-box stats">
                <h3>統計資料</h3>
                <div class="stat-item">
                    <div class="stat-label">總轉動次數</div>
                    <div class="stat-value">876,232,497</div>
                </div>
                <div class="stat-item">
                    <div class="stat-label">轉動時數</div>
                    <div class="stat-value">2,433,979</div>
                </div>
                <div class="stat-item">
                    <div class="stat-label">線上用戶</div>
                    <div class="stat-value" id="onlineUsers">1,688</div>
                </div>
            </div>
        </div>
    </div>

    <!-- 中獎者彈窗 -->
    <div id="winnerModal" class="modal">
        <h2>恭喜！</h2>
        <div class="winner" id="winnerName"></div>
        <button onclick="closeModal('close')">關閉</button>
        <button onclick="closeModal('remove')">移除</button>
    </div>

    <script>
        const canvas = document.getElementById('wheelCanvas');
        const ctx = canvas.getContext('2d');
        const audio = document.getElementById('spinSound');
        
        let soundEnabled = false;
        let isSpinning = false;
        let currentRotation = 0;
        let spinSpeed = 0;
        
        // 轉盤選項
        let options = ['Eric', 'Farina', 'Gabriel', 'Hannah', 'Ali', 'Bertz', 'Charles', 'Diana'];
        const colors = ['#4169E1', '#DC143C', '#FFD700', '#32CD32'];
        
        function drawWheel() {
            // 清除整個畫布
            ctx.clearRect(0, 0, canvas.width, canvas.height);
            
            // 保存當前狀態
            ctx.save();
            
            // 移動到畫布中心
            ctx.translate(canvas.width/2, canvas.height/2);
            
            // 應用當前旋轉
            ctx.rotate(currentRotation);
            
            const sliceAngle = (2 * Math.PI) / options.length;
            
            // 繪製每個扇形
            options.forEach((option, i) => {
                ctx.beginPath();
                ctx.fillStyle = colors[i % colors.length];
                ctx.moveTo(0, 0);
                ctx.arc(0, 0, 200, i * sliceAngle, (i + 1) * sliceAngle);
                ctx.lineTo(0, 0);
                ctx.fill();
                
                // 繪製文字
                ctx.save();
                ctx.rotate(i * sliceAngle + sliceAngle/2);
                ctx.fillStyle = '#FFF';
                ctx.font = '20px Arial';
                ctx.textAlign = 'right';
                ctx.fillText(option, 180, 10);
                ctx.restore();
            });
            
            // 恢復到初始狀態
            ctx.restore();
            
            // 繪製指針
            ctx.save();
            ctx.translate(canvas.width/2 + 200, canvas.height/2);
            
            ctx.beginPath();
            ctx.fillStyle = '#999999';
            ctx.strokeStyle = '#000';
            ctx.lineWidth = 2;
            ctx.moveTo(0, -10);
            ctx.lineTo(-15, 0);
            ctx.lineTo(0, 10);
            ctx.closePath();
            ctx.fill();
            ctx.stroke();
            
            ctx.restore();
        }
        
        function toggleSound() {
            soundEnabled = !soundEnabled;
            const soundBtn = document.querySelector('.sound-btn');
            
            if (soundEnabled) {
                soundBtn.classList.add('enabled');
                document.getElementById('spinSound').load();
                document.getElementById('applauseSound').load();
            } else {
                soundBtn.classList.remove('enabled');
                const spinSound = document.getElementById('spinSound');
                const applauseSound = document.getElementById('applauseSound');
                
                spinSound.pause();
                spinSound.currentTime = 0;
                applauseSound.pause();
                applauseSound.currentTime = 0;
            }
            
            localStorage.setItem('wheelSoundEnabled', soundEnabled);
        }
        
        function createFirework(x, y) {
            // 創建一個容器來存放所有煙花粒
            const container = document.createElement('div');
            container.style.position = 'fixed';  // 使用fixed而不absolute
            container.style.left = '0';
            container.style.top = '0';
            container.style.width = '100%';
            container.style.height = '100%';
            container.style.pointerEvents = 'none';
            container.style.zIndex = '1000';
            document.body.appendChild(container);
            
            const colors = ['#ff0000', '#ffff00', '#00ff00', '#0000ff', '#ff00ff'];
            const particles = [];
            
            for (let i = 0; i < 30; i++) {
                const particle = document.createElement('div');
                particle.className = 'firework';
                container.appendChild(particle);  // 添加到容器中而不是body
                
                const angle = (Math.PI * 2 * i) / 30;
                const velocity = 10;
                const color = colors[Math.floor(Math.random() * colors.length)];
                
                let posX = x;
                let posY = y;
                let velocityX = Math.cos(angle) * velocity;
                let velocityY = Math.sin(angle) * velocity;
                
                particle.style.position = 'fixed';  // 使用fixed定位
                particle.style.backgroundColor = color;
                particle.style.width = '4px';
                particle.style.height = '4px';
                particle.style.borderRadius = '50%';
                particle.style.transform = `translate(${posX}px, ${posY}px)`;  // 使transform代替left/top
                
                particles.push({
                    element: particle,
                    posX,
                    posY,
                    velocityX,
                    velocityY
                });
            }
            
            let animationFrame;
            const animate = () => {
                let allDone = true;
                
                particles.forEach(particle => {
                    particle.velocityY += 0.2;
                    particle.posX += particle.velocityX;
                    particle.posY += particle.velocityY;
                    
                    particle.element.style.transform = `translate(${particle.posX}px, ${particle.posY}px)`;
                    
                    if (particle.posY < window.innerHeight) {
                        allDone = false;
                    }
                });
                
                if (!allDone) {
                    animationFrame = requestAnimationFrame(animate);
                } else {
                    cancelAnimationFrame(animationFrame);
                    container.remove();  // 一次性移除整個容器
                }
            };
            
            animate();
        }
        
        function showWinner(winner) {
            const modal = document.getElementById('winnerModal');
            const winnerName = document.getElementById('winnerName');
            const applause = document.getElementById('applauseSound');
            
            modal.style.display = 'block';
            winnerName.textContent = winner;
            
            // 播放掌聲音效
            if (soundEnabled) {  // 用與轉盤相同的聲開關
                applause.currentTime = 0;  // 重置音頻
                applause.play().catch(error => {
                    console.log('Failed to play applause:', error);
                });
            }
            
            // 減少煙花數量，增加間隔時間
            for (let i = 0; i < 3; i++) {
                setTimeout(() => {
                    createFirework(
                        window.innerWidth * 0.3 + (Math.random() * window.innerWidth * 0.4),
                        window.innerHeight * 0.3
                    );
                }, i * 500);
            }
            
            updateResults(winner);
        }
        
        function closeModal(action) {
            const modal = document.getElementById('winnerModal');
            const winner = document.getElementById('winnerName').textContent;
            const applause = document.getElementById('applauseSound');
            
            // 停止掌聲音效
            applause.pause();
            applause.currentTime = 0;
            
            modal.style.display = 'none';
            
            if (action === 'remove') {
                removeWinnerFromEntries(winner);
                updateResults(winner);
                document.querySelector('[data-tab="results"]').click();
            }
        }
        
        let shouldStop = false;
        let extraRotation = false;  // 添加額外旋轉標記

        function handleSpinClick() {
            const spinBtn = document.querySelector('.spin-btn');
            
            if (!isSpinning) {
                // 開始旋轉
                spinBtn.textContent = '停止';
                spinBtn.setAttribute('data-state', 'stop');
                spinWheel();
            } else {
                // 請求停止
                spinBtn.textContent = '停止中...';
                spinBtn.disabled = true;
                shouldStop = true;
                extraRotation = true;
            }
        }

        function spinWheel() {
            if(isSpinning) return;
            
            if(soundEnabled) {
                audio.play();
            }
            
            isSpinning = true;
            shouldStop = false;
            extraRotation = false;
            spinSpeed = 0.5;
            let totalRotation = 0;
            let extraRotationStarted = false;  // 標記是否開始額外旋轉
            
            function animate() {
                currentRotation += spinSpeed;
                
                // 如果請求停止，處理額外旋轉
                if (shouldStop) {
                    if (extraRotation && !extraRotationStarted && spinSpeed < 0.3) {
                        // 開始額外旋轉
                        extraRotationStarted = true;
                        spinSpeed = Math.max(spinSpeed, 0.2);  // 確保有足夠的速度完成額外旋轉
                        totalRotation = 0;  // 重置旋轉計數
                    } else if (extraRotationStarted && totalRotation >= 2 * Math.PI) {
                        // 完成一圈額外旋轉後，開始最終減速
                        extraRotation = false;
                        spinSpeed *= 0.97;
                    } else {
                        // 正常減速
                        spinSpeed *= 0.98;
                    }
                } else {
                    // 正常旋轉速度
                    spinSpeed *= 0.995;
                }
                
                totalRotation += spinSpeed;
                drawWheel();
                
                // 修改停止條件
                const shouldContinue = spinSpeed > 0.001 && 
                    (!shouldStop || spinSpeed > 0.02 || 
                     (extraRotationStarted && totalRotation < 2 * Math.PI));
                
                if(shouldContinue) {
                    requestAnimationFrame(animate);
                } else {
                    isSpinning = false;
                    if(soundEnabled) {
                        audio.pause();
                        audio.currentTime = 0;
                    }
                    
                    const degrees = (currentRotation * 180 / Math.PI) % 360;
                    const sliceDegrees = 360 / options.length;
                    const winnerIndex = Math.floor(((360 - degrees) % 360) / sliceDegrees);
                    const winner = options[winnerIndex];
                    
                    // 重置按鈕狀態
                    const spinBtn = document.querySelector('.spin-btn');
                    spinBtn.textContent = '開始轉動';
                    spinBtn.removeAttribute('data-state');
                    spinBtn.disabled = false;
                    
                    setTimeout(() => showWinner(winner), 500);
                }
            }
            
            animate();
        }
        
        // 更新獲取選項的函數
        function getEntries() {
            const textarea = document.querySelector('.entries-textarea');
            return textarea.value.split('\n').filter(name => name.trim());
        }

        // 修移除中獎者的函數
        function removeWinnerFromEntries(winner) {
            const textarea = document.querySelector('.entries-textarea');
            const entries = textarea.value.split('\n');
            const filteredEntries = entries.filter(entry => entry.trim() !== winner);
            textarea.value = filteredEntries.join('\n');
            
            // 更新計數
            updateEntriesCount();
            
            // 更新轉盤選項
            options = getEntries();
            drawWheel();
        }

        // 添加文本區域變聽
        document.querySelector('.entries-textarea').addEventListener('input', () => {
            updateEntriesCount();
            options = getEntries();
            drawWheel();
        });

        // 初始化時更新計數和選項
        document.addEventListener('DOMContentLoaded', () => {
            // 初始化轉盤
            drawWheel();
            
            // 從文本區域獲取初始選項
            const textarea = document.querySelector('.entries-textarea');
            if (textarea) {
                options = textarea.value.split('\n').filter(name => name.trim());
                drawWheel();
            }
            
            // 更新計數
            updateEntriesCount();
        });
        
        // 模擬線上用戶數量變化
        function updateOnlineUsers() {
            const element = document.getElementById('onlineUsers');
            const currentUsers = parseInt(element.textContent.replace(',', ''));
            const change = Math.floor(Math.random() * 11) - 5; // -5 到 +5 的隨機變化
            const newUsers = Math.max(1000, currentUsers + change);
            element.textContent = newUsers.toLocaleString();
        }
        
        // 每5秒更新一次線上用戶數
        setInterval(updateOnlineUsers, 5000);
        
        // 標籤頁切換功能
        document.querySelectorAll('.tab-btn').forEach(button => {
            button.addEventListener('click', () => {
                // 移除所有活動狀
                document.querySelectorAll('.tab-btn').forEach(btn => btn.classList.remove('active'));
                document.querySelectorAll('.tab-pane').forEach(pane => pane.classList.remove('active'));
                
                // 添加新活動狀態
                button.classList.add('active');
                document.getElementById(`${button.dataset.tab}-tab`).classList.add('active');
            });
        });

        // 添加新條目功能
        document.querySelector('.add-entry-btn').addEventListener('click', () => {
            const entriesList = document.querySelector('.entries-list');
            const newEntry = document.createElement('div');
            newEntry.className = 'entry-item';
            newEntry.innerHTML = `<input type="text" class="entry-input" placeholder="Enter name">`;
            entriesList.appendChild(newEntry);
            
            // 更新計數
            updateEntriesCount();
        });

        // 更新條目計數
        function updateEntriesCount() {
            const entries = getEntries();
            document.querySelector('[data-tab="entries"] .count').textContent = entries.length;
        }

        // 修改現有的 updateResults 函數
        function updateResults(winner) {
            const currentDate = new Date().toLocaleTimeString();
            const newEntry = `${currentDate} - ${winner}\n`;
            
            const textarea = document.querySelector('.results-textarea');
            textarea.value = newEntry + textarea.value;
            
            // 更新結果計數
            const resultCount = textarea.value.split('\n').filter(line => line.trim()).length;
            document.querySelector('[data-tab="results"] .count').textContent = resultCount;
        }
        
        // 語言切換功能
        function changeLanguage(lang) {
            console.log(`Changing language to: ${lang}`);
            // 這裡添加語言切換的具體實現
        }
        
        // 分享功能
        function shareWheel() {
            // 實現分享功能
            const shareData = {
                title: 'Wheel of Names',
                text: 'Check out my wheel!',
                url: window.location.href
            };
            
            if (navigator.share) {
                navigator.share(shareData);
            } else {
                // 回退到複製連結
                navigator.clipboard.writeText(window.location.href);
                alert('已複製連結！');
            }
        }
        
        // 添加複製結果功
        document.querySelector('.results-textarea').addEventListener('click', function() {
            this.select();
            try {
                document.execCommand('copy');
                // 可以添加一個小提示表明已複製
                const originalBg = this.style.backgroundColor;
                this.style.backgroundColor = '#e8f0fe';
                setTimeout(() => {
                    this.style.backgroundColor = originalBg;
                }, 200);
            } catch (err) {
                console.error('Failed to copy text');
            }
        });

        // 添加輸入驗證
        document.getElementById('rotationInput').addEventListener('input', function() {
            let value = parseInt(this.value) || 7;
            value = Math.min(Math.max(value, 3), 20);
            if (this.value !== value.toString()) {
                this.value = value;
            }
        });

        // 簡化 initializeWheel 函數
        function initializeWheel() {
            // 初始化轉盤
            drawWheel();
            
            // 從文本區域獲取初始選項
            const textarea = document.querySelector('.entries-textarea');
            if (textarea) {
                options = textarea.value.split('\n').filter(name => name.trim());
                drawWheel();
            }
            
            // 更新計數
            updateEntriesCount();
        }

        // 確保在 DOM 加載完成後初始化
        document.addEventListener('DOMContentLoaded', function() {
            initializeWheel();
            
            // 恢復聲音設置
            const savedSoundState = localStorage.getItem('wheelSoundEnabled');
            if (savedSoundState === 'true') {
                soundEnabled = true;
                const soundBtn = document.querySelector('.sound-btn');
                const soundText = soundBtn.querySelector('.sound-text');
                soundBtn.classList.add('enabled');
                soundText.textContent = '音效開啟';
            }
        });

        // 如果 DOM 已經加載完成，直接初始化
        if (document.readyState !== 'loading') {
            initializeWheel();
        }

        // 自動調整文本框高度的函數
        function autoResizeTextarea(textarea) {
            // 重置高度
            textarea.style.height = 'auto';
            
            // 計算新高度
            const newHeight = Math.min(
                Math.max(textarea.scrollHeight, 100),  // 不小於最小高度
                400  // 不超過最大高度
            );
            
            textarea.style.height = newHeight + 'px';
            
            // 如果內容超過最大高度，顯示滾動條
            textarea.style.overflowY = newHeight === 400 ? 'auto' : 'hidden';
        }

        // 在 DOMContentLoaded 事件中添加監聽器
        document.addEventListener('DOMContentLoaded', function() {
            const textarea = document.querySelector('.entries-textarea');
            if (textarea) {
                // 初始調整
                autoResizeTextarea(textarea);

                // 監聽輸入事件
                textarea.addEventListener('input', function() {
                    autoResizeTextarea(this);
                });

                // 監聽值變化事件
                textarea.addEventListener('change', function() {
                    autoResizeTextarea(this);
                });

                // 監聽粘貼事件
                textarea.addEventListener('paste', function() {
                    setTimeout(() => autoResizeTextarea(this), 0);
                });
            }
        });

        // 修改現有的 updateEntriesCount 函數
        function updateEntriesCount() {
            const entries = getEntries();
            document.querySelector('[data-tab="entries"] .count').textContent = entries.length;
            
            // 更新文本框高度
            const textarea = document.querySelector('.entries-textarea');
            if (textarea) {
                autoResizeTextarea(textarea);
            }
        }

        // 添加觸摸設備支持
        document.addEventListener('DOMContentLoaded', function() {
            if ('ontouchstart' in window) {
                const dropdownContainer = document.querySelector('.dropdown-container');
                const menuToggle = document.querySelector('.menu-toggle');
                
                menuToggle.addEventListener('click', function(e) {
                    e.preventDefault();
                    dropdownContainer.classList.toggle('touch-active');
                });

                // 點擊外部關閉選單
                document.addEventListener('click', function(e) {
                    if (!dropdownContainer.contains(e.target)) {
                        dropdownContainer.classList.remove('touch-active');
                    }
                });
            }
        });

        function toggleMenu() {
            const menu = document.querySelector('.nav-menu');
            const toggle = document.querySelector('.menu-toggle');
            
            menu.classList.toggle('active');
            toggle.classList.toggle('active');
            
            // 點擊外部關閉選單
            function closeMenu(e) {
                if (!menu.contains(e.target) && !toggle.contains(e.target)) {
                    menu.classList.remove('active');
                    toggle.classList.remove('active');
                    document.removeEventListener('click', closeMenu);
                }
            }
            
            // 添加點擊事件監聽器
            setTimeout(() => {
                document.addEventListener('click', closeMenu);
            }, 0);
        }
    </script>
</body>
</html>
